package autotest_util

import (
	app_global "app/app_src/framework/app/global"
	"os"
	"strings"
)

// 调整应用目录
func AdjustAppDir() {
	appDir := CalcAppDir()

	app_global.InitGlobal(appDir, "")
}

// 根据当前执行目录计算新的应用目录
func CalcAppDir() string {
	currDir, err := os.Getwd()
	if err != nil {
		panic(err)
	}

	return _GetAppDir(currDir)
}

func _GetAppDir(currDir string) string {
	currDir = strings.ReplaceAll(currDir, "\\", "/")
	index := strings.LastIndex(currDir, "/app_src/")

	if index == -1 {
		panic(`not found "/app_src/" in path "` + currDir + `"`)
	}

	return currDir[0 : index+1]
}
